package service;

import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.Iterator;

@WebServlet("/demo4")
public class ServletDemo4 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        System.out.println("demo4************");
        /*获取请求参数的通用方式*/
        //1:String getParmeter(String name) 根据参数名称获取参数值
//      req.setCharacterEncoding("utf-8");
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        System.out.println(username);
        System.out.println(password);
/*根据参数名称获取参数值的数组        String         getParameterValues*/
        String[] hobbies = req.getParameterValues("hobby");
       for(String s:hobbies){
           System.out.println(s);
       }
       /*获取请求转发器对象*/
        /*存储资源*/
        /*void  setAttribute(String name,Object obj)：存储数据*/
        RequestDispatcher requestDispatcher = req.getRequestDispatcher("/demo5");
    requestDispatcher.forward(req,resp);
req.setAttribute("name",username);
req.setAttribute("password",password);





    }
}
